﻿using System;
using System.Windows.Data;

namespace MediaBrowserSL.RIA.Converters
{
    /// <summary>
    /// Date Converter
    /// </summary>
    public class DateConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
            object parameter, System.Globalization.CultureInfo culture)
        {
            DateTime dt = (DateTime)value;
            return dt.ToShortDateString();
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, System.Globalization.CultureInfo culture)
        {
            string str = value.ToString();
            DateTime dt = DateTime.MinValue;

            if (DateTime.TryParse(str, out dt))
            {
                return dt;
            }
            return value;
        }
    }
}
